package com.mobilekites.util;

import android.content.Context;
import android.content.SharedPreferences;

public interface KitesPrefers {
	public void storeRegistrationIdGCM(String regId);

	public String getRegistrationIdGCM();

	public void storeRegistrationIdVersion(int versionApp);

	public int getRegistrationIdVersion();

	public void saveShowMoreApp(boolean showMore);

	public boolean isShowMoreApp();

	public void saveAbout(String about);

	public String getAbout();

	public void saveAdmob(String admobId);

	public String getAdmobId();

	public void saveOtherAppUrl(String url);

	public String getOtherAppUrl();

	public interface AdOldPrefers {
		public void setIsPromoteApp(boolean isPrmote);

		public boolean isPromoteApp();

		public void savePromoteURL(String url);

		public String getPromoteURL();

		public void savePromoteTitle(String tile);

		public String getPromoteTitle();

		public void savePromoteMessage(String message);

		public String getPromoteMessage();

		public void setUpdate(boolean isUpdate);

		public boolean hasUpdate();

		public void setAppVersionServer(int versionServer);

		public int getAppVersionServer();

		public void setUpdateMessage(String message);

		public String getUpdateMessage();

		public void setForceUpdate(int forceUpdate);

		public int isForceUpdate();

		public void setUpdateURL(String url);

		public String getUpdateURL();

	}

	public static class AdOldPrefersImpl implements AdOldPrefers {
		private SharedPreferences mPrefers;
		private SharedPreferences.Editor mEditor;

		public AdOldPrefersImpl(Context context) {
			mPrefers = context.getSharedPreferences("kites_config",
					Context.MODE_PRIVATE);
			mEditor = mPrefers.edit();
		}

		@Override
		public void setIsPromoteApp(boolean isPromote) {
			mEditor.putBoolean("adold_ispromote", isPromote).commit();
		}

		@Override
		public boolean isPromoteApp() {
			return mPrefers.getBoolean("adold_ispromote", false);
		}

		@Override
		public void savePromoteURL(String url) {
			mEditor.putString("adold_promote_url", url).commit();
		}

		@Override
		public String getPromoteURL() {
			return mPrefers.getString("adold_promote_url",
					"http://mobilekites.com");
		}

		@Override
		public void savePromoteTitle(String tile) {
			mEditor.putString("adold_promote_title", tile).commit();
		}

		@Override
		public String getPromoteTitle() {
			return mPrefers.getString("adold_promote_title", "");
		}

		@Override
		public void savePromoteMessage(String message) {
			mEditor.putString("adold_promote_msg", message).commit();
		}

		@Override
		public String getPromoteMessage() {
			return mPrefers.getString("adold_promote_msg", "");
		}

		@Override
		public void setUpdate(boolean isUpdate) {
			mEditor.putBoolean("adold_isupdate", isUpdate).commit();
		}

		@Override
		public boolean hasUpdate() {
			return mPrefers.getBoolean("adold_isupdate", false);
		}

		@Override
		public void setAppVersionServer(int versionServer) {
			mEditor.putInt("adold_appversion_server", versionServer).commit();
		}

		@Override
		public int getAppVersionServer() {
			return mPrefers
					.getInt("adold_appversion_server", Integer.MIN_VALUE);
		}

		@Override
		public void setUpdateMessage(String message) {
			mEditor.putString("adold_update_msg", message).commit();

		}

		@Override
		public String getUpdateMessage() {
			return mPrefers.getString("adold_update_msg", "");
		}

		@Override
		public void setForceUpdate(int forceUpdate) {
			mEditor.putInt("adold_forceupdate", forceUpdate).commit();
		}

		@Override
		public int isForceUpdate() {
			return mPrefers.getInt("adold_forceupdate", 0);
		}

		@Override
		public void setUpdateURL(String url) {
			mEditor.putString("adold_update_url", url).commit();
		}

		@Override
		public String getUpdateURL() {
			return mPrefers.getString("adold_update_url",
					"http://mobilekites.com");
		}

	}

	public static class KitesPrefersImpl implements KitesPrefers {
		private Context mContext;
		private SharedPreferences mPrefers;
		private SharedPreferences.Editor mEditor;

		public KitesPrefersImpl(Context context) {
			mPrefers = context.getSharedPreferences("kites_config",
					Context.MODE_PRIVATE);
			mEditor = mPrefers.edit();
			mContext = context;
		}

		public void storeRegistrationIdGCM(String regId) {
			mEditor.putString("gcm_regId", regId).commit();
		}

		public String getRegistrationIdGCM() {
			int currentVerion = Utility.getAppVersion(mContext);
			int registrationIdVersion = getRegistrationIdVersion();
			if (currentVerion > registrationIdVersion) {
				return "";
			}
			return mPrefers.getString("gcm_regId", "");
		}

		public void storeRegistrationIdVersion(int versionApp) {
			mEditor.putInt("gcm_regIdVersion", versionApp).commit();
		}

		public int getRegistrationIdVersion() {
			return mPrefers.getInt("gcm_regIdVersion", Integer.MIN_VALUE);
		}

		@Override
		public void saveShowMoreApp(boolean showMore) {
			mEditor.putBoolean("kites_show_more_app", showMore).commit();
		}

		@Override
		public boolean isShowMoreApp() {
			return mPrefers.getBoolean("kites_show_more_app", false);
		}

		@Override
		public void saveAbout(String about) {
			mEditor.putString("kites_about", about).commit();
		}

		@Override
		public String getAbout() {
			return mPrefers.getString("kites_about", "");
		}

		@Override
		public void saveAdmob(String admobId) {
			mEditor.putString("kites_adm", admobId).commit();
		}

		@Override
		public String getAdmobId() {
			return mPrefers.getString("kites_adm", "");
		}

		@Override
		public void saveOtherAppUrl(String url) {
			mEditor.putString("kites_other_app_url", url).commit();

		}

		@Override
		public String getOtherAppUrl() {
			return mPrefers.getString("kites_other_app_url",
					"http://mobilekites.com");
		}

	}
}
